package J1202_night;

import java.util.Stack;
//栈是一种数据结构
//虚拟机栈是JVM的内存
//栈帧是调用方法的时候，开辟的内存
public class MinStack {
    Stack<Integer> stack = new Stack<>();
    Stack<Integer> minstack = new Stack<>();
    public void push(int val) {
        stack.push(val);
        if(minstack.empty()) {
            minstack.push(val);
        } else {
            if(val <= minstack.peek()) {
                minstack.push(val);
            }
        }
    }
    public void pop() {
        int popMin = minstack.peek();
        int pop = stack.pop();
        if(pop == popMin) {
            minstack.pop();
        }
    }
    public int top() {
        return stack.peek();
    }
    public int getMin() {
        return minstack.peek();
    }
}
